﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using YWTSSys.Model;
using YWTSSys.BLL;
namespace YWTSSys.Web.MachineSys
{
    public partial class UpdateInitPwd : PageBase
    {
        protected override string DWZRef
        {
            get { return ""; }
        }
        protected override bool MustLogin
        {
            get
            {
                return true;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            OUserInfo obj = OUserController.CurrentUser;
            string _oldpwd = obj.PassWord;
            string oldpwd = GetRequestValue<string>("oldpwd","");
            string newpwd = GetRequestValue<string>("newpwd", "");
            string newpwd2 = GetRequestValue<string>("newpwd2", "");
            if(_oldpwd!=oldpwd)
            {
                lbmsg.Text = "请输入正确的原密码";
                return;
            }
            if (newpwd == _oldpwd)
            {
                lbmsg.Text = "新密码与原密码一致，请重输";
                return;
            }

            if (newpwd != newpwd2)
            {
                lbmsg.Text = "两次新密码不一致，请重输";
                return;
            }


           bool t= OUserController.EditPwd(obj.UserId, newpwd);
           if (t)
           {
               OUserController.LoginOut();
               Response.Redirect(this.ResolveUrl("~/MachineSys/login.aspx?errormsg="+HttpUtility.HtmlDecode("请使用新密码登陆")));
           }
           else
           {
            lbmsg.Text = "更改失败，请重试";
           }
        }
    }
}